"""
@file_path: 文件名
@sheet_name：表名
@row_read_index ：从第几行读取
return: 返回列表里面嵌套元组
"""
import os

import xlrd
# 以下仅供参考
def read_excel(file_path:str, sheet_name, row_read_index=1) -> list[tuple]:
    #获取项目的绝对路径
    file_path=file_path.lstrip("../").lstrip("./") #去除..或者.
    base_dir=os.path.dirname(os.path.dirname(__file__))
    file=os.path.join(base_dir,file_path) #二个路径做拼接
    wb = xlrd.open_workbook(file)  #../
    sheet = wb.sheet_by_name(sheet_name)
    data = []
    for i in range(row_read_index, sheet.nrows):
        data.append(tuple(sheet.row_values(i)))
    return data
    # return [tuple(sheet.row_values(i)) for i in range(row_read_index, sheet.nrows)]

# # print(read_excel("../data/test_data.xls", "login_data"))
# print(os.path.dirname(os.path.dirname(__file__))) # ../../
# print(Path(__file__).parent.parent)

if __name__ == '__main__':

    file_path="./data/test_data.xls" #去除..或者.
    # file_path=file_path.lstrip("..")
    aaa=r"D:\PycharmProjects\20250909\PythonProject20250909"
    file=os.path.join(aaa,file_path)
    print(file)

